<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/26
 * Time: 14:14
 */

/**
 * Class Involved_ProjectModel
 */

class Involved_ProjectModel extends BaseModel
{

    protected $table = 'project';

    /**
     * 获取首页央票通和上市通
     */
    public function YptProjectList($page){
        #分页
        $pge=$page;
        $page = empty($pge)?1:$pge;//页数
        $count = DB::table($this->table)
            ->join('company','company.company_name','=','project.company_name')
            ->count();
        $numfenye=ceil($count/HostEnum::PAGE_NUM);
        if($page>$numfenye){
            $list=[];
            return $list;
        }else{
            $offset = ($page-1) * HostEnum::PAGE_NUM;//分页数
            $list = DB::table($this->table)
                ->select('project_id','project_name','project.company_name','project.limit','project.yield_rate','project.start_time','project.end_time','project_scale','project.created','project.agent_bank','project.rank','project.type','project.plate')//字段
                ->join('company','company.company_name','=','project.company_name')
                ->orderBy('created','dessc')
                ->skip($offset)->take(HostEnum::PAGE_NUM)
                ->get();
            return $list;

        }

    }
    /**
     * 获取央票通列表页
     */
    public function YptProjectData($page){
        #分页
        $pge=$page;
        $page = empty($pge)?1:$pge;//页数
        $count = DB::table($this->table)
            ->join('company','company.company_name','=','project.company_name')
            ->where('project.type','1')
            ->count();
        $numfenye=ceil($count/HostEnum::PAGE_NUM);
        if($page>$numfenye){
            $list=[];
            return $list;
        }else{
            $offset = ($page-1) * HostEnum::PAGE_NUM;//分页数
            $list = DB::table($this->table)
                ->select('project_id','project_name','project.company_name','project.limit','project.yield_rate','project.start_time','project.end_time','project_scale','project.created','project.agent_bank','project.rank','project.type')//字段
                ->join('company','company.company_name','=','project.company_name')
                ->where('project.type','1')
                ->orderBy('created','desc')
                ->skip($offset)->take(HostEnum::PAGE_NUM)
                ->get();
            return $list;
        }

    }
    /**
     * 获取上市通列表页
     */
    public function SstProjectData($page){
        #分页
        $pge=$page;
        $page = empty($pge)?1:$pge;//页数
        $count = DB::table($this->table)
            ->join('company','company.company_name','=','project.company_name')
            ->where('project.type','2')
            ->count();
        $numfenye=ceil($count/HostEnum::PAGE_NUM);
        if($page>$numfenye){
            $list=[];
            return $list;
        }else{
            $offset = ($page-1) * HostEnum::PAGE_NUM;//分页数
            $list = DB::table($this->table)
                ->select('project_id','project_name','project.company_name','project.limit','project.yield_rate','project.start_time','project.end_time','project_scale','project.created','project.agent_bank','project.plate','project.type')//字段
                ->join('company','company.company_name','=','project.company_name')
                ->where('project.type','2')
                ->orderBy('created','desc')
                ->skip($offset)->take(HostEnum::PAGE_NUM)
                ->get();
            return $list;
        }
    }

    /**
     * 获取央票通详情页
     */
    public function YptProjectdetailsData($project_id){
        $list =DB::table($this->table)
            ->select('project.project_id','project.status','project.project_name','project.company_name','project.limit','project.yield_rate','project.start_time','project.end_time','project.project_scale','project.created','project.agent_bank','project.rank','project.content','purpose','factoring_company','image1','image2','img1','img2','img3','brief','partner_id','pay_id','refund_source','risk_safeguard','payer_risk','past_risk','organ_risk')//字段
            ->join('company','company.company_name','=','project.company_name')
            ->where('project_id',$project_id)
            ->get();
        return $list;
    }

    /**
     * 获取一条信息
     */
    public function GetdetailsData($project_id,$type){
        $list =DB::table($this->table)
            ->select('project_id','project_name','project.company_name','project.limit','project.yield_rate','project.start_time','project.end_time','project_scale','project.created','project.agent_bank','project.rank','project.type')//字段
            // ->join('company','company.company_name','=','project.company_name')
            ->where(['project_id'=>$project_id,'type'=>$type])
            ->get();
        return $list;
    }

    /**
     * 获取一条信息
     */
    public function GetdetailsDataone($project_id,$type){
        $list =DB::table($this->table)
            ->select('project_id','project_name','project.company_name','project.limit','project.yield_rate','project.start_time','project.end_time','project_scale','project.created','project.agent_bank','project.rank','project.type')//字段
            // ->join('company','company.company_name','=','project.company_name')
            ->where(['project_id'=>$project_id,'type'=>$type])
            ->first();
        return $list;
    }



}